/*
 * @Author: ljkt
 * @Version: 1.0
 * @Date: 2022-01-06 15:57:15
 * @LastEditors: ljkt
 * @LastEditTime: 2025-03-01 23:33:27
 * @Description:
 */
#include "./Common_Include.h"
void App_Main_Log(void)
{
	//static Ram unsigned char tx[45] = {0};
	//static unsigned short tick = 0;
	//unsigned char i = 0;
	// static unsigned char cnt = 0;
	// 83333
	//if (Drv_Autoload_Ntick_u16(&tick, 100ul))
	//{

//		tx[i++] = 0xf5;
//		tx[i++] = 0xfa;
//		tx[i++] = sizeof(tx);
		// ==================数据区
		// tx[i++] = (unsigned char)(gDrvPwm[e_INDEX_PWM_FORWARD].Duty >> 8); // 0
		// tx[i++] = (unsigned char)(gDrvPwm[e_INDEX_PWM_FORWARD].Duty);
		// tx[i++] = (unsigned char)(gDrvPwm[e_INDEX_PWM_BACKWARD].Duty >> 8); // 1
		// tx[i++] = (unsigned char)(gDrvPwm[e_INDEX_PWM_BACKWARD].Duty);
		// tx[i++] = (unsigned char)(gDrvIoO[e_INDEX_IOO_FORWARD_EN].IoOut >> 8); // 2
		// tx[i++] = (unsigned char)(gDrvIoO[e_INDEX_IOO_FORWARD_EN].IoOut);
		// tx[i++] = (unsigned char)(gDrvIoO[e_INDEX_IOO_BACKWARD_EN].IoOut >> 8); // 3
		// tx[i++] = (unsigned char)(gDrvIoO[e_INDEX_IOO_BACKWARD_EN].IoOut);
		// tx[i++] = (unsigned char)(gDrvIoI[e_INDEX_IOI_CHARGE_STATUS].State >> 8); // 4
		// tx[i++] = (unsigned char)(gDrvIoI[e_INDEX_IOI_CHARGE_STATUS].State);
		// tx[i++] = (unsigned char)(gDrvAdc[e_INDEX_ADC_BATTERY_MV].Avg >> 8); // 5
		// tx[i++] = (unsigned char)(gDrvAdc[e_INDEX_ADC_BATTERY_MV].Avg);
		// tx[i++] = (unsigned char)((gDev_HBrideg.EVN_TIME) >> 8); // 6
		// tx[i++] = (unsigned char)((gDev_HBrideg.EVN_TIME));
		// tx[i++] = (unsigned char)(gApp_Sys.Motor_Adc_mV >> 8); // 7
		// tx[i++] = (unsigned char)(gApp_Sys.Motor_Adc_mV);
		// tx[i++] = (unsigned char)(gDev_HBrideg.Avg_mA >> 8); // 8
		// tx[i++] = (unsigned char)(gDev_HBrideg.Avg_mA);
		// tx[i++] = (unsigned char)(gApp_Sys.Dc_mV >> 8); // 9
		// tx[i++] = (unsigned char)(gApp_Sys.Dc_mV);
		// tx[i++] = (unsigned char)(gDev_HBrideg.Pulse_mA >> 8); // 10
		// tx[i++] = (unsigned char)(gDev_HBrideg.Pulse_mA);
		// tx[i++] = (unsigned char)(gApp_Sys.McuVcc_mV >> 8); // 11
		// tx[i++] = (unsigned char)(gApp_Sys.McuVcc_mV);
		// tx[i++] = (unsigned char)(gApp_Sys.Battery_mV >> 8); // 12
		// tx[i++] = (unsigned char)(gApp_Sys.Battery_mV);
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_x_u16 >> 8); // 13
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_x_u16);
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_y_u16 >> 8); // 14
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_y_u16);
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_z_u16 >> 8); // 15
		// tx[i++] = (unsigned char)(gDevIcm42688.acc_z_u16);
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_x_u16 >> 8); // 16
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_x_u16);
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_y_u16 >> 8); // 17
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_y_u16);
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_z_u16 >> 8); // 18
		// tx[i++] = (unsigned char)(gDevIcm42688.gyro_z_u16);
		// tx[i++] = (unsigned char)(cnt >> 8); // 19
		// tx[i++] = (unsigned char)(cnt);
		// cnt++;

		// =====================
		//tx[sizeof(tx) - 2] = (unsigned char)(CheckSum_u16(tx, sizeof(tx) - 2));
		//tx[sizeof(tx) - 1] = 0 - tx[sizeof(tx) - 2];
		// Dev_IoPrint_Hex(tx, sizeof(tx));
		//  Dev_IoPrint_Baud();
	//}
	//Dev_IoPrint_Scan(); // 日志输出扫描
}

void App_Main_Init(void)
{
	SET_GLOBAL_IE(REF_FALSE);
#if defined(EN_CLK)
	Hal_Clk_Init(); // 时钟初始化
#endif

#ifdef EN_IOO
	Drv_IoO_Init(); // 输入控制
#endif
	Drv_SysTick_Init(); // 系统滴答初始化
#if defined(EN_TIMER0) || defined(EN_TIMER1) || defined(EN_TIMER2) || defined(EN_TIMER3)
	Drv_Tmrx_Init();
#endif

#if defined(EN_PWM0) || defined(EN_PWM1) || defined(EN_PWM2)
	Drv_Pwmx_Init(); // PWM初始化
#endif
#if defined(EN_IAP_E2PROM) || defined(EN_IAP_FLASH)
	Drv_Flash_Read();
#endif
#ifdef EN_IOI
	Drv_IoI_Init(); // 输入初始化
#endif

#ifdef EN_ADC
	Drv_Adc_Init(); // ADC初始化
#endif
#ifdef EN_I2C
	Drv_I2c_Init(); // I2C初始化
#endif
#if defined(EN_UART0) || defined(EN_UART1) || defined(EN_UART2) || defined(EN_UART3)
	Drv_Uartx_Init(); // 串口初始化
#endif
#ifdef EN_COM_SEG
	Drv_ComSeg_Init();
#endif
	Dev_IoPrint_Init(); // 日志初始化
	Dev_Key_Init();		// 按键初始化
	Dev_Buz_Init();
	Dev_CF_Init();

	App_Disp_Init();
	App_Com_Init();
	App_Sys_Init();
	App_Menu_Init();
}

void App_Main_Scan(void)
{
	Hal_Wtd_Feed(); // 喂狗
#if defined(EN_PWM0) || defined(EN_PWM1) || defined(EN_PWM2)
	Drv_Pwmx_Scan(); // PWM扫描
#endif
#ifdef EN_IOI
	Drv_IoI_Scan(); // 输入扫描
#endif
#ifdef EN_IOO
	Drv_IoO_Scan(); // 输出扫描
#endif
#ifdef EN_ADC
	Drv_Adc_Scan(); // ADC扫描
#endif
#if defined(EN_UART0) || defined(EN_UART1) || defined(EN_UART2) || defined(EN_UART3)
	Drv_Uartx_Scan(); // 串口初始化
#endif
	Dev_Key_Scan();	  // 按键扫描
	Dev_Buz_Scan();	  //
	Dev_C8624_Scan(); //

	App_Disp_Scan(); // 显示扫描
	App_Com_Scan();	 // 通信扫描
	App_Main_Log();	 // 变量参数
	App_Sys_Scan();	 // 系统参数
	App_Menu_Scan(); //
}
